package com.huaxinkai.utils;

import java.io.File;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

/**
 * JDBC 工具类
 * @author liuzh
 * @date 2017年5月7日
 */
public class JDBCUtils {

	public static  Connection getConnection(){
		
		/*
		String url = "jdbc:mysql:///huaxinkai?useSSL=true&serverTimezone=GMT";
		String user = "root";
		String password = "11324";
		String driver = "com.mysql.cj.jdbc.Driver";
		*/
		
		FileInputStream in = null;
		
		File file = null;
		
		Properties properties = new Properties();
		
		Connection connection = null;
		
		try {
			
			file = new File("src/com/huaxinkai/properties/jdbc.properties");
			
			in = new FileInputStream(file);
			
			properties.load(in);
			
			String url = properties.getProperty("jdbc.url");
			String user = properties.getProperty("jdbc.user");
			String password = properties.getProperty("jdbc.password");
			String driver = properties.getProperty("jdbc.driver");
			
			Class.forName(driver);
			
			connection = DriverManager.getConnection(url, user, password);
			
		} catch (Exception e) {
			
			e.printStackTrace();
		} 
		
		return connection;
		
	}
}
